/**
 * 
 */
var accountinfo;
	var edit;
	var url;
	var goback = true;
	
	$(function() {
		
		statusInit("valForm", accountinfo, edit);
		
		$.demonPlugin.formValidate("valForm");
		
		$("#saveAccount").click(goback, function(evt){
			if (!$("form").valid())
				return false;
			var formData = aoData = $.demonPlugin.collectFormData();
			$.demonPlugin.asyncData("PUT" , url, formData, 
					function(data){
						if (data.status == "ok"){
							alert("保存成功");
							if (evt.data)
								window.history.back();
						}else{
							alert(data.msg);
						}
					},
					function (data){
						alert('保存失败，请重试');
					});
		});
		
		$("#cancel").click(function(){
			window.history.back();
		});
		
		setHeight();
	})
	
	function statusInit(formId, accountinfo, edit){
		if (accountinfo && accountinfo!=""){
			$.demonPlugin.initForm(formId, accountinfo, edit);
			if (edit!="true"){
				$("#saveAccount").css("display", "none");
			}else{
				url = "saveaccount";
			}
		}else{
			url = "addaccount";
		}
	}